package com.study.testSpringBoot.login;

import cn.hutool.core.util.StrUtil;
import org.springframework.web.servlet.LocaleResolver;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Locale;

/**
 * @author wc_phz
 * @ClassName MyLocalResolver
 * @Description: [ ]
 * @date 2020/4/2 15:56
 */
public class MyLocalResolver implements LocaleResolver {
    @Override
    public Locale resolveLocale(HttpServletRequest request) {
        System.out.println("解析语言。。。");
        String language = request.getParameter("language");
        Locale locale = Locale.getDefault();
        if (StrUtil.isNotBlank(language)) {
            String[] split = language.split("_");
            locale = new Locale(split[0], split[1]);
        }
        return locale;
    }

    @Override
    public void setLocale(HttpServletRequest request, HttpServletResponse response, Locale locale) {
        System.out.println("设置语言。。。");
    }
}
